var a = getApp();

Page({
  data: {
    zgzimgurl1: "", //医师资格证1
    zgzimgurl2: "", //医师资格证2
    zczimgurl: "", //医师职称证
    sfzimgurl1: "", //身份证1
    sfzimgurl2: "", //身份证2
    gzzimgurl: "", //工作证
    zkbianhao: "", //资格证编号
    sfzbianhao: "", //身份证编号
    zgzimgurl1back: "", //医师资格证1
    zgzimgurl2back: "", //医师资格证2
    zczimgurlback: "", //医师职称证
    sfzimgurl1back: "", //身份证1
    sfzimgurl2back: "", //身份证2
    gzzimgurlback: "", //工作证
    img: "",
    WGender: [],
    WGenderID: [],
    WGendertext: "",
    WGenderIDID: "",
    Whospital: "",
    office: "",
    Wclasses: ["医生", "护士"],
    WclassesText: "",
    jobType: "",
    WpostID: [],
    WpostText: "",
    WpostTextID: "",
    bgGoodAt: "",
    Wcertificate: "请完善",
    name: "",
    identityCard: "",
    show: !0,
    show1: !0,
    briefIntroduce: "",
    num: 0,
    numText: "已认证",
    array: ['男', '女'], //性别
    index: 0, //性别
    arrays: ['综合医院', '中医医院', '中西医结合医院', '民族医医院', '专科医院', '康复医院', '妇幼保健院', '中心卫生院', '乡（镇）卫生院', '街道卫生院', '疗养院'], //类别
    indexs: 0, //类别
    title: [], //职称
    index2: 0, //职称
    disease: ['感冒', '接骨'], //擅长疾病
    index3: 0, //擅长疾病
    IMG1: '/assets/images/head.png',
    IMG2: '/assets/images/head.png'
  },
  zkbianhao: function(e) {
    this.setData({
      zkbianhao: e.detail.value
    })
  },
  sfzbianhao: function(e) {
    this.setData({
      sfzbianhao: e.detail.value
    })
  },
  name: function(e) {
    let val = e.detail.value;
    this.setData({
      name: val
    })
  },
  input: function(e) {
    console.log(e)
    var that = this
    var z_zhenzhi = e.detail.value
    that.setData({
      z_zhenzhi: z_zhenzhi
    })
  },


  //更换医生头像
  replace: function() {
    var that = this;
    var uniacid = a.siteInfo.uniacid;
    var zhuanjiaImg = that.data.zhuanjiaImg;
    var openid = wx.getStorageSync('openid')
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function(res) {
        // console.log(res)
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var imgUrl = res.tempFilePaths[0];
        //console.log(tempFilePaths);
        wx.uploadFile({
          url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
          filePath: imgUrl,
          name: 'upfile',
          formData: {
            'path': 'wxchat'
          },
          success: function(res) {
            console.log(res.data)
            that.setData({
              uplogo: res.data,
              z_thumbs: imgUrl
            })
          },
          fail: function(res) {
            console.log(res)
          },
        })
        that.setData({
          logo: imgUrl
        })
      }
    })
  },
  //性别
  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为')
    if (e.detail.value == 0) {
      var z_sex = 0
    } else {
      var z_sex = 1
    }
    let array = this.data.array[e.detail.value];
    this.setData({
      index: e.detail.value,
      WGendertext: array,
      z_sex: z_sex
    })
  },
  //类别
  bindPickerChange2: function(e) {
    let arrays = this.data.arrays[e.detail.value];
    this.setData({
      indexs: e.detail.value,
      WclassesText: arrays
    })
  },
  //职称
  bindPickerChange3: function(e) {
    let title = this.data.title[e.detail.value];
    this.setData({
      index2: e.detail.value,
      WpostText: title
    })
  },
  //擅长疾病
  bindPickerChange4: function(e) {
    let title = this.data.title[e.detail.value];
    this.setData({
      index3: e.detail.value,
      bgGoodAt: title
    })
  },
  //身份证
  identityCard: function(e) {
    console.log(e)
    let val = e.detail.value;
    let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if (reg.test(val) === false) {
      wx.showToast({
        title: "身份证错误",
        icon: "none",
        duration: 2e3
      })
    } else {
      this.setData({
        zjshenfenz: val
      })
    }
  },
  imgQualifications: function() {
    let that = this;
    wx.chooseImage({
      count: 1, // 最多可以选择的图片张数，默认9
      sizeType: ['original', 'compressed'], // original 原图，compressed 压缩图，默认二者都有
      sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
      success: function(res) {
        console.log(res)
        let tempFilePaths = res.tempFilePaths[0];
        that.setData({
          IMG1: tempFilePaths
        })
      }
    })
  },
  uploadimgs(e) {
    var uniacid = a.siteInfo.uniacid;
    let t = this,
      m = e.currentTarget.dataset.mnames;
    wx.chooseImage({
      count: 1, // 最多可以选择的图片张数，默认9
      sizeType: ['original', 'compressed'], // original 原图，compressed 压缩图，默认二者都有
      sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
      success: function(res) {
        let tempFilePaths = res.tempFilePaths[0];
        wx.uploadFile({
          url: t.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
          filePath: tempFilePaths,
          name: 'upfile',
          formData: {},
          success: function(res) {
            console.log(res)
            "zgzimgurl1" == m ? t.setData({

              zgzimgurl1: tempFilePaths,
              zgzimgurl1back: res.data,
            }) : "zgzimgurl2" == m ? t.setData({
              zgzimgurl2: tempFilePaths,
              zgzimgurl2back: res.data,
            }) : "zczimgurl" == m ? t.setData({
              zczimgurl: tempFilePaths,
              zczimgurlback: res.data,
            }) : "sfzimgurl1" == m ? t.setData({
              sfzimgurl1: tempFilePaths,
              sfzimgurl1back: res.data,
            }) : "sfzimgurl2" == m ? t.setData({
              sfzimgurl2: tempFilePaths,
              sfzimgurl2back: res.data,
            }) : "gzzimgurl" == m ? t.setData({
              gzzimgurl: tempFilePaths,
              gzzimgurlback: res.data,
            }) : console.log(m);
          },
          fail: function(res) {
            console.log(res)
          },
        })
      }
    })
  },
  imgQualifications2: function() {
    let that = this;
    wx.chooseImage({
      count: 1, // 最多可以选择的图片张数，默认9
      sizeType: ['original', 'compressed'], // original 原图，compressed 压缩图，默认二者都有
      sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
      success: function(res) {
        console.log(res)
        let tempFilePaths = res.tempFilePaths[0];
        that.setData({
          IMG2: tempFilePaths
        })
      }
    })
  },
  WZsz: function(a) {
    var that = this
    var zid = that.data.zid
    wx.setStorageSync("url", "doctor/info/update/"), wx.navigateTo({
      url: "/hyb_yl/backstageLifes/pages/WapproveSz/WapproveSz?zid=" + zid
    });
  },
  Wimg: function(t) {
    var e = this;
    e.setData({
      num: 0,
      numText: "保存"
    }), wx.chooseImage({
      count: 1,
      sizeType: ["orignal", "compressed"],
      sourceType: ["album", "camera"],
      success: function(t) {
        console.log(t.tempFilePaths[0]), e.setData({
          z_thumbs: t.tempFilePaths[0],
          show: !1
        });
        var o = wx.getStorageSync("log") || "";
      }
    });
  },
  Whospital: function(a) {
    this.setData({
      num: 0,
      numText: "保存"
    }), wx.setStorageSync("url", "doctor/info/update/"), wx.navigateTo({
      url: "/hyb_yl/backstageLifes/pages/WapproveWhospital/WapproveWhospital"
    });
  },
  WadministrativeOffice: function(e) {
    var hosid = e.currentTarget.dataset.hosid
    console.log(hosid)
    if (!hosid) {
      wx.showToast({
        title: "请先选择医院",
        icon: "none",
        duration: 2e3
      })
    } else {
      wx.navigateTo({
        url: "/hyb_yl/backstageLifes/pages/WapproveWhospitaloffice/WapproveWhospitaloffice?hosid=" + hosid
      });
    }

  },
  z_name: function(e) {
    console.log(e)
    var that = this
    that.setData({
      z_name: e.detail.value
    })
  },
  bgGoodAt: function(a) {
    this.setData({
      num: 0,
      numText: "保存"
    }), wx.setStorageSync("url", "doctor/info/update/");
    var t = this;
    "" != t.data.jobType ? (wx.setStorageSync("jobType", t.data.jobType), wx.navigateTo({
      url: "/hyb_yl/index/WapproveJ/WapproveJ"
    })) : "" == t.data.jobType && wx.showModal({
      title: "提示",
      content: "请选着类别",
      success: function(a) {
        a.confirm ? console.log("用户点击确定") : a.cancel && console.log("用户点击取消");
      }
    });
  },

  WTT: function(e) {
    let that = this;
    var zid = that.data.zid
    var zjshenfenz = that.data.zjshenfenz //身份证
    var z_telephone = that.data.z_telephone //电话
    var z_content = that.data.z_content //简介
    var z_yiyuan = that.data.z_yiyuan
    var nksname = that.data.nksname
    var z_sex = that.data.z_sex
    var nksid = that.data.nksid
    var hosid = that.data.hosid
    var WpostText = that.data.WpostText //职称
    var z_name = that.data.z_name
    var z_zhenzhi = that.data.z_zhenzhi
    var zgzimgurl1back = that.data.zgzimgurl1back; //医师资格证1
    var zgzimgurl2back = that.data.zgzimgurl2back; //医师资格证2
    var zczimgurlback = that.data.zczimgurlback; //医师职称证
    var sfzimgurl1back = that.data.sfzimgurl1back; //身份证1
    var sfzimgurl2back = that.data.sfzimgurl2back; //身份证2
    var gzzimgurlback = that.data.gzzimgurlback; //工作证
    var zkbianhao = that.data.zkbianhao; //资格证编号
    var sfzbianhao = that.data.sfzbianhao; //身份证编号
    if (!that.data.uplogo) {
      var z_thumbs = that.data.z_thumbsback
    } else {
      var z_thumbs = that.data.uplogo
    }
    if (z_name == "") {
      wx.showToast({
        title: "姓名不能为空",
        icon: "none",
        duration: 2e3
      })
    } else if (z_sex == "") {
      wx.showToast({
        title: "请选择性别",
        icon: "none",
        duration: 2e3
      })
    } else if (zjshenfenz == "" || zjshenfenz == undefined) {
      wx.showToast({
        title: "请填写身份证",
        icon: "none",
        duration: 2e3
      })
    } else if (z_yiyuan == "") {
      wx.showToast({
        title: "请选择医院",
        icon: "none",
        duration: 2e3
      })
    } else if (WpostText == "") {
      wx.showToast({
        title: "请选择职称",
        icon: "none",
        duration: 2e3
      })
    } else if (z_zhenzhi == "" || z_zhenzhi == undefined) {
      wx.showToast({
        title: "擅长疾病不能为空",
        icon: "none",
        duration: 2e3
      })
    } else if (z_content == "" || z_content == undefined) {
      wx.showToast({
        title: "请填写个人简介",
        icon: "none",
        duration: 2e3
      })
    } else if (zkbianhao == "") {
      wx.showToast({
        title: "请填写资格证编号",
        icon: "none",
        duration: 2e3
      })
    } else if (zgzimgurl1back == "") {
      wx.showToast({
        title: "请上传资格证",
        icon: "none",
        duration: 2e3
      })
    } else if (zgzimgurl2back == "") {
      wx.showToast({
        title: "请上传资格证",
        icon: "none",
        duration: 2e3
      })
    } else if (zczimgurlback == "") {
      wx.showToast({
        title: "请上传医师证",
        icon: "none",
        duration: 2e3
      })
    } else if (sfzbianhao == "") {
      wx.showToast({
        title: "请填写身份证号",
        icon: "none",
        duration: 2e3
      })
    } else if (sfzimgurl1back == "") {
      wx.showToast({
        title: "请上传身份证",
        icon: "none",
        duration: 2e3
      })
    } else if (sfzimgurl2back == "") {
      wx.showToast({
        title: "请上传身份证",
        icon: "none",
        duration: 2e3
      })
    } else if (gzzimgurlback == "") {
      wx.showToast({
        title: "请上传工作证",
        icon: "none",
        duration: 2e3
      })
    } else {
      wx.showModal({
        title: '提示',
        content: ' 确认提交么？ ',
        success: function(res) {
          if (res.confirm) {
            // console.log('用户点击确定');
            var that = this;
            var values = e.detail.value;
            a.util.request({
              url: 'entry/wxapp/Regin.zhuce',
              data: {
                zid: zid,
                zjshenfenz: zjshenfenz, //身份证
                z_telephone: z_telephone, //电话
                z_content: z_content, //简介
                z_yiyuan: z_yiyuan,
                nksname: nksname,
                z_sex: z_sex,
                nksid: nksid,
                hosid: hosid,
                z_zhicheng: WpostText, //职称
                z_name: z_name,
                z_zhenzhi: z_zhenzhi,
                z_thumbs: z_thumbs,
                openid: wx.getStorageSync('openid'),
                zgzimgurl1back: zgzimgurl1back, //医师资格证1
                zgzimgurl2back: zgzimgurl2back, //医师资格证2
                zczimgurlback: zczimgurlback, //医师职称证
                sfzimgurl1back: sfzimgurl1back, //身份证1
                sfzimgurl2back: sfzimgurl2back, //身份证2
                gzzimgurlback: gzzimgurlback, //工作证
                zkbianhao: zkbianhao, //资格证编号
                sfzbianhao: sfzbianhao, //身份证编号
              },
              header: {
                'Content-Type': 'application/json'
              },
              success: function(res) {
                //console.log(res)
                wx.showToast({
                  title: "提交成功",
                  icon: "none",
                  duration: 2e3,
                  success: function() {
                    setTimeout(function() {
                      wx.navigateBack({
                        delta: 1
                      });
                    }, 2000)
                  }
                })
              },
              fail: function(err) {
                console.log(err);
              }
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      });
    }

  },
  onLoad: function(t) {
    var that = this
    var zid = t.zid
    if (t.numText) {
      var numText = t.numText
      that.setData({
        numText: numText
      })
    }
    a.util.request({
      'url': 'entry/wxapp/Hzbingli.url',
      success: function(res) {
        that.setData({
          url: res.data,
          imgurl: res.data + "attachment/"
        })
      },
    })
    a.util.request({
      'url': 'entry/wxapp/Regin.zjinfo',
      'data': {
        id: zid
      },
      success: function(res) {
        console.log(res)
        var z_sex = res.data.z_sex
        if (z_sex == 0) {
          var index = '女'
        }
        if (z_sex == 1) {
          var index = '男'
        }
        var id = res.data.z_room
        that.setData({
          userinfo: res.data,
          index: index,
          touxiangurl: res.data.z_thumbs,
          z_thumbs: res.data.z_thumbs,
          z_thumbsback: res.data.z_thumbsback,
          z_name: res.data.z_name,
          z_telephone: res.data.z_telephone,
          z_yiyuan: res.data.z_yiyuan,
          nksname: res.data.nksname,
          z_content: res.data.z_content,
          z_thumb: res.data.z_thumb,
          hosid: res.data.hosid,
          nksid: res.data.nksid,
          WpostText: res.data.z_zhicheng,
          z_zhenzhi: res.data.z_zhenzhi,
          zjshenfenz: res.data.zjshenfenz,
          zgzimgurl1: res.data.zgzimgurl1back, //医师资格证1
          zgzimgurl2: res.data.zgzimgurl2back, //医师资格证2
          zczimgurl: res.data.zczimgurlback, //医师职称证
          sfzimgurl1: res.data.sfzimgurl1back, //身份证1
          sfzimgurl2: res.data.sfzimgurl2back, //身份证2
          gzzimgurl: res.data.gzzimgurlback, //工作证
          zkbianhao: res.data.zkbianhao, //资格证编号
          sfzbianhao: res.data.sfzbianhao, //身份证编号
        })
      },
      fail: function(err) {
        console.log(err)
      },

    })
    that.getaBase()
    that.setData({
      zid: zid
    })
  },

  onShow: function() {
    var that = this
    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];
    if (currPage.data.id && currPage.data.name) {
      that.setData({ //将携带的参数赋值
        hosid: currPage.data.id,
        z_yiyuan: currPage.data.name
      })
    }
    if (currPage.data.lat && currPage.data.lng) {
      that.setData({ //将携带的参数赋值
        lat: currPage.data.lat,
        lng: currPage.data.lng,
      })
    }

    if (currPage.data.introduce) {
      console.log(currPage.data.introduce)
      that.setData({ //将携带的参数赋值
        z_content: currPage.data.introduce,
      })
    }
    if (currPage.data.z_telephone) {
      that.setData({ //将携带的参数赋值
        z_telephone: currPage.data.z_telephone,
      })
    }
    if (currPage.data.nksinfo) {
      that.setData({ //将携带的参数赋值
        nksinfo: currPage.data.nksinfo,
        nksid: currPage.data.nksinfo.id,
        nksname: currPage.data.nksinfo.name
      })
    }
  },
  getaBase() {
    var that = this
    a.util.request({
      'url': 'entry/wxapp/Index.base',
      success: function(res) {
        console.log(res)
        that.setData({
          title: res.data.zhciheng
        })
      }
    })
  }
});